public class ListTest {
    public ListTest() {
    }

    // 合并两个有序链表
    public static MySingleList.ListNode mergeTwoLists(MySingleList.ListNode head1, MySingleList.ListNode head2) {
        MySingleList.ListNode newHead = new MySingleList.ListNode(-1);
        MySingleList.ListNode tmp = newHead;

        while (head1 != null && head2 != null) {
            if (head1.val > head2.val) {
                tmp.next = head2;
                head2 = head2.next;
            } else {
                tmp.next = head1;
                head1 = head1.next;
            }
            tmp = tmp.next;
        }
        if (head1 != null) {
            tmp.next = head1;
        } else {
            tmp.next = head2;
        }
        return newHead.next;
    }

    public static void main(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(1);
        mySingleList1.addLast(2);
        mySingleList1.addLast(4);
        MySingleList mySingleList2 = new MySingleList();
        mySingleList2.addLast(1);
        mySingleList2.addLast(3);
        mySingleList2.addLast(4);

        mySingleList1.display();
        mySingleList2.display();
        MySingleList mySingleList3 = new MySingleList();


    }
    public static void main1(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.createList();
        mySingleList.display();
        System.out.println("长度为:" + mySingleList.size());
        System.out.println(mySingleList.contains(12));
        System.out.println("===========================");
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addFirst(1);
        mySingleList1.addFirst(2);
        mySingleList1.addFirst(3);
        mySingleList1.addFirst(4);
        mySingleList1.display();
        System.out.println("===========================");
        MySingleList mySingleList2 = new MySingleList();
        mySingleList2.addLast(11);
        mySingleList2.addLast(22);
        mySingleList2.addLast(33);
        mySingleList2.addLast(44);
        mySingleList2.display();
        mySingleList2.addIndex(2, 9999);
        mySingleList2.display();
        mySingleList2.remove(9999);
        mySingleList2.display();
    }
}
